<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="基础练习/时钟.html">
    <input type="text" id="txt">
    <input type="submit" id="btn" value="按钮">
    <a href="javascript:void(0);">哈哈哈哈</a>
    <a href="javascript:;">哈哈哈哈</a>

</form>
<script>
    var txt = document.getElementById('txt');
    var btn = document.getElementById('btn');

    //阻止默认事件 return false;||preventDefault();IE8不支持||e.returnValue=false;三个方法


    btn.onclick=function (e) {
        e=e||window.event;
        if(e.preventDefault){
            e.preventDefault();
        }else{
            e.returnValue=false;
        }
        txt.value="哈哈哈";
        e.returnValue=false;
    }

    // btn.onclick = function (e) {
    //     e = e || window.event;
    //     e.stopPropagation();
    //     var target = e.target || e.srcElement;
    //
    //     // console.log(e.bubbles);
    // }
    // txt.onfocus = function (e) {
    //     e = e || window.event;
    //     var target = e.target || e.srcElement;
    //     if (e.stopPropagation) {
    //         e.stopPropagation();
    //     } else {
    //         e.cancelBubble = true;
    //     }
    //     console.log(e.eventPhase);
    // }
    // txt.addEventListener('click', function (e) {
    //
    // }, true);
    //console.log(e.bubbles);   以下返回false：focus、scroll、blur
    //阻止冒泡  stopPropagation()
    //阻止冒泡还能阻止其他同一事件被调用  stopImmediatePropagation();
    //取消冒泡事件  cancelBubble=true;默认false
    // document.body.addEventListener('click', function (e) {
    //     e = e || window.event;
    //     var target = e.target || e.srcElement;
    //     if (e.stopPropagation) {
    //         e.stopPropagation();
    //     } else {
    //         e.cancelBubble = true;
    //     }
    //     console.log(e.eventPhase);
    // },true)
</script>
</body>
</html>